/**正则表达式 */
/**手机*/
export const phoneReg = /^1[3|4|5|7|8|9][0-9]\d{8}$/
/**邮编*/
export const postCode = /^[0-9][0-9]{5}$/

/**数字*/
export const numberReg = /^(\d+)$/
function required(data = '必须输入') {
    return [{
        required: true,
        trigger: 'change',
        message: data
    }]
}

function min(min = 6, type = '密码') {
    return [{
        min: min,
        message: `${type}长度不小于${min}位`,
        trigger: 'blur'
    }]
}

function pattern(reg, message, trigger = 'blur') {
    return [{
        pattern: reg,
        message: message,
        trigger: trigger
    }]
}


/**必填 */
export const requiredInput = (data) => {
    return required(data)
}


/**
 * 验证手机号
 */
export const phone = () => {
    var valid = required('请输入手机号')
    //测试期间注释本句代码
    //valid = valid.concat(pattern(phoneReg, '手机号格式不正确'))
    return valid
}

/**
 * 数字
 */
export const isNumber = (msg) => {
    var valid = required('价格不能为空')
    valid = valid.concat([{
        type: 'number', trigger: 'change', message: msg, transform(value) {
            return Number(value);
        }
    }])
    return valid
}


/**
 * 密码验证
 */
export const password = () => {
    var valid = required('请输入密码')
    valid = valid.concat(min());
    return valid
}